import wmi

def get_cpu_temperature():
    # 使用原始字符串格式以避免转义问题
    w = wmi.WMI(namespace=r"root\wmi")
    # 获取 CPU 温度信息
    temperature_info = w.MSAcpi_ThermalZone()
    for temp in temperature_info:
        # 通常返回的温度是以开尔文为单位，转换为摄氏度
        return temp.CurrentTemperature / 10.0 - 273.15

temperature = get_cpu_temperature()
if temperature is not None:
    print(f"CPU Temperature: {temperature:.2f}°C")
else:
    print("Could not get CPU temperature.")